﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Principal;
using System.Net;
using System.Xml.Linq;
using System.ServiceModel;

namespace SPServicesTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSPListsServices_Click(object sender, EventArgs e)
        {
            SPListsService.ListsSoapClient lsc = new SPListsService.ListsSoapClient();
            lsc.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
            lsc.ClientCredentials.Windows.ClientCredential = new NetworkCredential("administrator", "K00fax", "moss2010-hn");
            XElement xe = lsc.GetList("Test1");
        }

        private void btnSPListsService2_Click(object sender, EventArgs e)
        {
            EndpointAddress endpointAddress = new EndpointAddress("https://moss2010-hn/_vti_bin/lists.asmx");
            
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Name = "ListsSoap";
            //binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; //http
            binding.Security.Mode = BasicHttpSecurityMode.Transport; //https
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

            SPListsService.ListsSoapClient lsc = new SPListsService.ListsSoapClient(binding, endpointAddress);
            lsc.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
            //lsc.ClientCredentials.Windows.ClientCredential = new NetworkCredential("administrator", "K00fax", "moss2010-hn");

            //integrated authentication
            String sCurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
            lsc.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

            XElement xe = lsc.GetList("Test1");
        }
    }
}
